package com.company.OfferGuide;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class 字符串的排列 {

    Set<String> strings = new TreeSet<>();
    public String[] permutation(String s) {

        if (s == null || s.length() == 0) return new String[]{};

        boolean[] visited = new boolean[s.length()];

        help(s,"",visited);

        String[] res = new String[this.strings.size()];
        return strings.toArray(res);


    }

    private void help(String s, String s1, boolean[] visited) {
        if (s1.length() == s.length()) strings.add(s1);

        for (int i = 0; i < s.length(); i++) {
            if (visited[i]) continue;
            visited[i] = true;
            help(s, s1 +s.charAt(i), visited);
            visited[i] = false;
        }


    }


}
